package com.site.util;

import java.util.ArrayList;

/**
 * 优化CSS与JS的输出
 * @author Believe fate
 *
 */
public class AddCssScript {
   /**
    * 加载公共的CSS
    * @return link html
    */
   public static String CSS(){
	   String output = "";
       ArrayList<String> arrCss = new ArrayList<String>();
       arrCss.add("common.css");
       for(int i = 0; i < arrCss.size(); i++){
    	   output += "<link href='"+Common.base_url+"/css/"+arrCss.get(i)+"' rel='stylesheet' type='text/css' />";
       }
	   return output;
   }
   /**
    * 加载公共的JS
    * @return script html
    */
   public static String Script(){
	   String output = "";
	   ArrayList<String> arrScr = new ArrayList<String>();
	   arrScr.add("jquery-1.4.2.min.js");
	   arrScr.add("common.js");
	   //arrScr.add("modelDialogBox.js");
	   for(int i = 0; i < arrScr.size(); i++){
		   output += "<script type='text/javascript' src='"+Common.base_url+"/js/"+arrScr.get(i)+"'></script>";
	   }
	   return output;
   }
   /**
    * 根据每个不同的页面加载不同的CSS
    * @param pagename 页面名称
    * @return link html
    */
   public static String CSS(String pagename){
	   String output = "";
	   String [] op = {
           "products"
	   };
	   ArrayList<SCMap> cssList = new ArrayList<SCMap>();
	   for(int j = 0; j < op.length; j++){
		   String cssFileName = op[j]+".css";
		   SCMap permission_map = new SCMap();
		   permission_map.setKey(op[j]);
		   permission_map.setValue(cssFileName);
		   cssList.add(permission_map);
	   }
	   for(int i = 0; i < cssList.size(); i++){
		   SCMap map = cssList.get(i);
		   if(pagename.equals(map.getKey())){
			   output += "<link href='"+Common.base_url+"/css/"+map.getValue().toString()+"' rel='stylesheet' type='text/css' />";
		   }
	   }
	   output = (CSS()+output);
	   return output;
   }
   /**
    * 根据不同的页面加载不同的JS文件 
    * @param pagename 页面名称
    * @return script html
    */
   public static String Script(String pagename){
	   String output = "";
	   String [] op = {
			   "login",
			   "top",
			   "left",
			   "termSelect",
			   "score",
			   "contestType",
			   "contestSection",
			   "enroll",
			   "users",
			   "vocabulary",
			   "termData",
			   "turnType",
			   "enrollGroups",
			   "round",
			   "xz"
	   };	   
	   ArrayList<SCMap> jsList = new ArrayList<SCMap>();
	   for(int j = 0; j < op.length; j++){
		   String jsFileName = op[j].toString()+".js";
		   SCMap permission_map = new SCMap();
		   permission_map.setKey(op[j]);
		   permission_map.setValue(jsFileName);
		   jsList.add(permission_map);
	   }
	   for(int i = 0; i< jsList.size(); i++){
		   SCMap map = jsList.get(i);
		   if(pagename.equals(map.getKey())){
			   output += "<script type='text/javascript' src='"+Common.base_url+"/js/"+map.getValue().toString()+"'></script>";
		   }
	   }
	   output = (Script()+output);
	   return output;
   }
   /**
    * 列表页面所需要的删除 JS
    * @param fornID 表单ID boxName  checkbox名称    action  删除的实现action 
    * @return script html
    */
   /*
   public static String DelScript(String formID,String boxName,String action){
	   String output = "";
	   output += "<script type='text/javascript'>";
	   		output += "$(function(){";
	   		
	   		output += "$('#add').click(function(){";
	   		    output += "$('#"+formID+"').attr('action','contestType/contestTypeAction!contestTypeAddPage')";
	   		    output += "$('#"+formID+"').submit()";
	   		output += "})";
	   		
	   		output += "$('#delete').click(function(){";
	   		    output += "var item = $('input[name='"+boxName+"']:checked').length";
	   		    output += "if(item > 0) {";
	   		    output += "$('#"+formID+"').attr('action','"+action+"')";
	   		    		output += "$('#"+formID+"').submit()";
	   		    output += "} else {";
	   		            output += "alert('您还没有选择要删除的数据！')";
	   		    output += "}";
				
	   	    output += "})";
	   	 output += "})";
	   output += "</script>";
	   return output;
   }
   */
}
